package fina2.dcs.security;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Remove;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.apache.log4j.Logger;
import org.jboss.annotation.ejb.LocalBinding;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Scope;


@Stateless
@Scope(ScopeType.SESSION)
@LocalBinding(jndiBinding = "UserRoleSession/local")
@AutoCreate
public class UserRoleSession implements UserRoleLocal,Serializable {
	@PersistenceContext
	private EntityManager em;

	@EJB
	private PermissionLocal permLocal;
	
	
	private Logger log=Logger.getLogger(getClass());

	public UserRole findByPk(UserRolePk pk) {
		return em.find(UserRole.class, pk);
	}

	public List<UserRole> findByUserId(BigDecimal userId) {
		List<UserRole> userRoles = null;
		try {
			userRoles = em.createQuery("FROM " + UserRole.class.getName() + " ur WHERE ur.userRolePk.userId=:userId").setParameter("userId", userId).getResultList();
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
		}
		return userRoles;
	}

	@Remove
	public void remove() {

	}

}
